# --coding=utf-8--
import os
import sys

from os.path import join

ROOT = "../evaluation"
LAT_FCTR = float(10000*1000*1000)  # num_operations 10000, num_pair_base 1000, 1s=1000ms
OPS_FCTR = float(10000*1000*1000*1000)


def read_file(filename):
    lines = []
    with open(filename, 'r') as f:
        for line in f:
            if line.startswith("Timer 13 MEAN"):
                lines.append(line)

    line = lines[-1]
    time = int(line.split(",")[0].split(":")[1])
    return time


def dataset(d):
    print("现在评估%s数据集上的性能" % d)
    baseline = read_file(join(ROOT, "{}_baseline.txt".format(d)))
    llsm_f = read_file(join(ROOT, "{}_llsm.txt".format(d)))
    llsm_l = read_file(join(ROOT, "{}_llsm_level.txt".format(d)))
    print("{} baseline latency: {:.2f} microseconds".format(d, baseline/LAT_FCTR))
    print("{} llsm (file) latency: {:.2f} microseconds".format(d, llsm_f/LAT_FCTR))
    print("{} llsm (level) latency: {:.2f} microseconds".format(d, llsm_l/LAT_FCTR))
    print("")


def main():
    if len(sys.argv) != 2:
        print("%s请输入数据集名称" % __file__)

    DataName = sys.argv[1]
    dataset(DataName)


if __name__ == '__main__':
    main()
